import { BaseItem } from "../common/BaseItem";
import { TSkill } from "../../../../Message/Db/Tables/TSkill";
import { SkillInfo } from "../../model/SkillInfo";
import { SkillLevelIcon } from "./SkillLevelIcon";
import { ImagesConst } from "../../resource/ImagesConst";
import { CDItemData } from "../../cache/CDItem/CDItemData";
import { SkillConfig } from "../../resource/SkillConfig";
import { ESkillUseType } from "../../../../Message/Public/ESkillUseType";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { CareerUtil } from "../common/util/CareerUtil";
import { SkillRules } from "../../rules/SkillRules";
import { ObjCreate } from "../common/ObjCreate";
import { Cache } from "../../cache/Cache";
import { Language } from "../../../../extend/language/Language";
import { DragManager } from "../../../../com/mui/manager/DragManager";
import { SkillAutoUseIcon } from "./SkillAutoUseIcon";
import { SkillIconInfo } from "../../model/SkillIconInfo";
type int = number;
//class SkillItem
    
    export  class SkillItem extends BaseItem
    {
        constructor()
        {
            super();
            this.setSize(32, 32);
            amountLabel.x = 0;
            amountLabel.y = 16;
            mouseChildren = true;
            return;
        }

        public set skillData(arg1: TSkill)
        {
            if (arg1) 
            {
                source = arg1.skillIcon.toString() + ".jpg";
            }
            else 
            {
                source = null;
            }
            return;
        }

        public get skillData(): TSkill
        {
            return (data as SkillInfo).tSkill;
        }

        public get skillInfo(): SkillInfo
        {
            return data as SkillInfo;
        }

        public set levelUpAble(arg1: Boolean)
        {
            if (arg1) 
            {
                if (!this._levelBody) 
                {
                    this._levelBody = new SkillLevelIcon();
                }
                if (data.learned) 
                {
                    this._levelBody.updateIcon(ImagesConst.skill_learnable);
                }
                else 
                {
                    this._levelBody.updateIcon(ImagesConst.skill_levelable);
                }
                if (!contains(this._levelBody)) 
                {
                    addChild(this._levelBody);
                }
                this._levelBody.x = 0;
                this._levelBody.y = 0;
            }
            else if (this._levelBody && contains(this._levelBody)) 
            {
                removeChild(this._levelBody);
            }
            return;
        }

        public set autoUseAble(arg1: Boolean)
        {
            return;
        }

        public set cdTime(arg1: CDItemData)
        {
            freezingEffect.cdTime = arg1;
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc1=null;
            super.data = arg1;
            this.skillData = (data as SkillInfo).tSkill;
            this._iconInfo = SkillConfig.instance.getIconType(this.skillInfo.skillCareer, this.skillInfo.position);
            if (!(this.skillInfo.useType == ESkillUseType._ESkillUseTypeAuto) && this._iconInfo) 
            {
                this._iconTxt.htmlText = HTMLUtil.addColor(this._iconInfo.iconName, CareerUtil.getSkillColorString());
                if (!contains(this._iconTxt)) 
                {
                    addChild(this._iconTxt);
                }
            }
            else if (contains(this._iconTxt)) 
            {
                removeChild(this._iconTxt);
            }
            if (SkillRules.OpenFromCareer && SkillRules.isCareerSkill(this.skillData) && !CareerUtil.isGradeCareer(this.skillInfo.skillCareer)) 
            {
                if (!this._compTxt) 
                {
                    this._compTxt = ObjCreate.createTextField("", 0, 0, this.width, 20, this);
                }
                if (!this._compTxt.parent) 
                {
                    addChild(this._compTxt);
                }
                loc1 = Cache.instance.career.getSkillInfo(this.skillInfo.position);
                if (!loc1 || loc1.skillLevel <= this.skillInfo.skillLevel && this.skillInfo.learned) 
                {
                    this._compTxt.htmlText = HTMLUtil.addColor(Language.getString(27514), "#00ff00");
                }
                else 
                {
                    this._compTxt.htmlText = HTMLUtil.addColor(loc1.skillLevel + Language.getString(27515), "#ff0000");
                }
                this._compTxt.x = (this.width - this._compTxt.textWidth) / 2 - 2;
            }
            else if (this._compTxt && this._compTxt.parent) 
            {
                removeChild(this._compTxt);
            }
            return;
        }

        public /* override */ set amount(arg1: int)
        {
            amountLabel.text = data.learned ? arg1 + "" : "0";
            return;
        }

        protected /* override */ onMouseDown(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (isDragAble && data.learned && data.dragAble) 
            {
                DragManager.instance.startDragItem(this);
            }
            return;
        }

        public /* override */ get dragSource(): Object
        {
            return data;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            this._iconTxt = ObjCreate.createTextField("", 17, 0, 20, 20, this);
            this._iconTxt.textColor = CareerUtil.getSkillColor();
            freezingEffect.setMaskSize(32, 32);
            return;
        }

        public /* override */ setSize(arg1: number, arg2: number): void
        {
            super.setSize(32, 32);
            if (freezingEffect) 
            {
                freezingEffect.x = 16;
                freezingEffect.y = 16;
            }
            return;
        }

        public /* override */ get width(): number
        {
            return 32;
        }

        public /* override */ get height(): number
        {
            return 32;
        }

        protected /* var */_levelBody: SkillLevelIcon;

        protected /* var */_autoUseIcon: SkillAutoUseIcon;

        protected /* var */_compTxt: Object /* flash.text.TextField */;

        protected /* var */_iconTxt: Object /* flash.text.TextField */;

        protected /* var */_iconInfo: SkillIconInfo;
    }
